package com.example.teacher

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.teacher.adapter.CourseStuListAdapter
import com.example.teacher.data.Class
import com.example.teacher.databinding.ActivityCourseDetailBinding
import com.example.teacher.http.OkHttp
import com.example.teacher.util.JsonUtil

/**
 * 课程详细信息
 */
class CourseDetailActivity : AppCompatActivity() {
    private lateinit var binding: ActivityCourseDetailBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        setContentView(R.layout.activity_course_detail)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_course_detail)

        binding.courseId.setText(intent.getStringExtra("courseId"))
        binding.courseName.setText(intent.getStringExtra("courseName"))
        binding.courseTeacher.setText(intent.getStringExtra("teacher")+"老师")
        binding.num.setText(intent.getStringExtra("courseNum"))
        binding.stuNum.setText("0")

        val res = OkHttp.getSync(
            "${BaseUrl.URL}${BaseUrl.GET_STUINFO_BY_COURSEID}" +
                    "?courseId=" + intent.getStringExtra("courseId")
        )
        if (res!=null){
            val resdata= JsonUtil.DataParse<Class>(res)

            binding.stuNum.setText(resdata.size.toString())

            val adapter=CourseStuListAdapter(resdata)
            binding.stuList.layoutManager=LinearLayoutManager(this)
            binding.stuList.adapter=adapter
        }else{
            Toast.makeText(this,"数据为空",Toast.LENGTH_SHORT).show()
        }
    }
}